package com.zx.mes.rabbitmq.hyl.topic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 主题 发送
 * @author hyl
 * @date 2018-3-19
 */
@Component
public class TopicSender {

    private static final Logger logger = LoggerFactory.getLogger(TopicSender.class);

    @Autowired
    private AmqpTemplate rabbitmqTemplate;

    public void send(){
        String context = "hi 所有的消息  只有接受2才能接受(topic.1)";
        logger.info("sender:{}",context);
        this.rabbitmqTemplate.convertAndSend("topicExchange","topic.1",context);
    }

    public void send1(){
        String context = "hi 所有的消息  1 接收1与接2都能接受(topic.message)";
        logger.info("sender:{}",context);
        this.rabbitmqTemplate.convertAndSend("topicExchange","topic.message",context);
    }

    public void send2(){
        String context = "hi 所有的消息  2  只有接收二才能接收";
        logger.info("sender:{}",context);
        this.rabbitmqTemplate.convertAndSend("topicExchange","topic.messages",context);
    }
}
